package org.xtense.rcp.editors;

import java.util.List;

import org.dom4j.Node;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;
import org.xtense.rcp.editors.util.XmlTreeProvider;
import org.xtense.rcp.util.XmlTreeUtil;

public class ResultViewer extends EditorPart {
	private TreeViewer treeViewer;

	@Override
	public void doSave(IProgressMonitor monitor) {
		//do nothing

	}

	@Override
	public void doSaveAs() {
		//do nothing

	}

	@Override
	public void init(IEditorSite site, IEditorInput input)
			throws PartInitException {
		this.setSite(site);
		this.setInput(input);

	}

	@Override
	public boolean isDirty() {
		//do nothing
		return false;
	}

	@Override
	public boolean isSaveAsAllowed() {
		//do nothing
		return false;
	}

	@Override
	public void createPartControl(Composite parent) {
		treeViewer = new TreeViewer(parent, SWT.NONE);

		Tree tree = treeViewer.getTree();
		TreeColumn tag = new TreeColumn(tree, SWT.LEAD);
		tag.setText(XmlEditor.Col_Name);
		tag.setWidth(250);
		TreeColumn value = new TreeColumn(tree, SWT.LEAD);
		value.setText(XmlEditor.Col_Value);
		value.setWidth(250);
		tree.setHeaderVisible(true);
		tree.setLinesVisible(true);
		treeViewer.setContentProvider(new XmlTreeProvider());
		treeViewer.setLabelProvider(new XmlTreeProvider());
		
	}
	
	@SuppressWarnings("unchecked")
	public void showResult(Object list) {
		if (list instanceof List)
			XmlTreeUtil.createXmlTree(treeViewer, (List<Node>) list);
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

}
